package cn.hengzhu.main_manager.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;

/**
 * Md5加密实现帮助�?
 * 
 * @author Administrator
 *
 */
public class Md5Util {

	public static final String SALT = "hz";// 盐??
	private static final int hashIterations = 10000;// 加密次数

	/**
	 * 通过MD5把content加密加盐后返回?
	 * 
	 * @param content
	 * @return
	 */
	public static String hash(String content) {
		ByteSource salt = ByteSource.Util.bytes(SALT);
		SimpleHash simpleHash = new SimpleHash("MD5", content, salt, hashIterations);
		return simpleHash.toString();
	}

	public static String wxXcxHash(String content) {
		SimpleHash simpleHash = new SimpleHash("MD5", content);
		return simpleHash.toString();
	}

	/**
	 * 密码开柜；对该密码进行md5
	 * 
	 * @author 周磊
	 * @since 2019年6月25日
	 * @param str
	 * @return
	 */
	public static String sha1(String str) {
		str = str + "skd.ohsiu9^%1";
		try {
			StringBuilder sb = new StringBuilder();
			MessageDigest digest = MessageDigest.getInstance("sha1");
			// 放入加密字符串
			digest.update(str.getBytes());
			// 进行加密
			byte[] digestMsg = digest.digest();
			// byte转换16进制
			for (byte b : digestMsg) {
				sb.append(String.format("%02x", b));
			}
			return sb.toString();
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		return str;
	}
}
